﻿using CommonBehaviors.Actions;
using Styx;
using Styx.Common;
using Styx.CommonBot;
using Styx.CommonBot.Routines;
using Styx.TreeSharp;
using Styx.WoWInternals;
using Styx.WoWInternals.WoWObjects;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Media;
using Action = Styx.TreeSharp.Action;

#region [Method] - Class Redundancy
using C = Ilusión.Rotation.Conditions;
using HkM = Ilusión.Core.Managers.Hotkey_Manager;
using SB = Ilusión.Core.Helpers.Spell_Book;
using TM = Ilusión.Core.Managers.Talent_Manager;
using U = Ilusión.Core.Unit;
using S = Ilusión.Core.Spell;
#endregion


namespace Ilusión.Rotation

{
    class Conditions
    {
        private static LocalPlayer Me { get { return StyxWoW.Me; } }
        private static WoWUnit currentTarget { get { return StyxWoW.Me.CurrentTarget; } }

        #region [Method] - Auto Attack
        private static Composite autoAttack()
        {
            return new Action(ret =>
            {
                if (!Me.IsAutoAttacking && U.isUnitValid(currentTarget, 40))
                    Lua.DoString("StartAttack()");
                return RunStatus.Failure;
            });
        }
        #endregion 

        #region [Method] - Devouring Plague 
        public static Composite DevouringPlague(WoWUnit Unit, double Range)
        {   /*devouring_plague,if=shadow_orb=3&(cooldown.mind_blast.remains<1.5|target.health.pct<20&cooldown.shadow_word_death.remains<1.5)*/
            return S.Cast(SB.spellDevouringPlague, ret => U.isUnitValid(Unit, Range) && U.ShadowOrb == 3 && S.cooldownTimeLeft(SB.spellMindBlast) < 1.5 | (Unit.HealthPercent < 20 && S.cooldownTimeLeft(SB.spellShadowWordDeath) < 1.5));
        }
        #endregion 

        #region [Method] - Devouring Plague Refresh
        public static Composite DevouringPlagueRefresh(WoWUnit Unit, double Range)
        {   /*devouring_plague,if=shadow_orb=3&ticks_remain<=1*/ 
            return S.Cast(SB.spellDevouringPlague, ret => U.isUnitValid(Unit, Range) && U.ShadowOrb == 3 && S.cooldownTimeLeft(SB.spellDevouringPlague) <= 1);
        }
        #endregion

        #region [Method] - Inner Fire
        public static Composite InnerFire()
        {   /*InnerFire*/
            return S.Buff(SB.auraInnerFire, ret => true);
        }
        #endregion

        #region [Method] - Mindbender
        public static Composite Mindbender(WoWUnit Unit, double Range)
        {   /*mindbender,if=talent.mindbender.enabled*/
            return S.Cast(SB.spellMindbender, ret => U.isUnitValid(Unit, Range) && TM.Mindbender);
        }
        #endregion

        #region [Method] - Power Infusion
        public static Composite PowerInfusion()
        {
            return S.blindCast(SB.spellPowerInfusion, ret => TM.PowerInfusion);
        }
        #endregion

        #region [Method] - Shadow Word Death
        public static Composite ShadowWordDeath(WoWUnit Unit, double Range)
        {   /*shadow_word_death,if=buff.shadow_word_death_reset_cooldown.stack=0&active_enemies<=5*/
            return S.Cast(SB.spellShadowWordDeath, ret => U.isUnitValid(Unit, Range) && Unit.HealthPercent < 20 /*&& U.activeEnemies() < = 5*/);
        }
        #endregion 

        #region [Method] - Shadow Word Death React
        public static Composite ShadowWordDeathReact(WoWUnit Unit, double Range)
        {   /*shadow_word_death,if=buff.shadow_word_death_reset_cooldown.stack=1&active_enemies<=5*/
            return S.Cast(SB.spellShadowWordDeath, ret => U.isUnitValid(Unit, Range) && Unit.HealthPercent < 20 && U.auraExists(Me, SB.auraShadowWordDeath) /*&& U.activeEnemies() < = 5*/);
        }
        #endregion 

        #region [Method] - Shadowfiend
        public static Composite Shadowfiend(WoWUnit Unit, double Range)
        {   /*shadowfiend,if=!talent.mindbender.enabled*/
            return S.Cast(SB.spellShadowfiend, ret => U.isUnitValid(Unit, Range));
        }
        #endregion

        #region [Method] - Shadowform
        public static Composite Shadowform()
        {   /*Shadowform*/
            return S.Buff(SB.auraShadowform, ret => true);
        }
        #endregion

        #region [Method] - Mind Blast
        public static Composite MindBlast(WoWUnit Unit, double Range)
        {   /*mind_blast,if=active_enemies<=5&cooldown_react*/
            return S.Cast(SB.spellMindBlast, ret => U.isUnitValid(Unit, Range)/* && U.activeEnemies() <= 5*/);
        }
        #endregion 

        #region [Method] - Mind Flay Insanity
        public static Composite MindFlay(WoWUnit Unit, double Range)
        {   /*mind_flay_insanity,if=target.dot.devouring_plague_tick.ticks_remain=1,chain=1*/
            return S.Cast(SB.spellMindFlay, ret => U.isUnitValid(Unit, Range) && S.cooldownTimeLeft(SB.auraDevouringPlague) >= 1 /*Chain = 1*/);
        }
        #endregion

        #region [Method] - Mind Flay Insanity Interrupt
        public static Composite MindFlayInterrupt(WoWUnit Unit, double Range)
        {   /*mind_flay_insanity,interrupt=1,chain=1,if=active_enemies<=5*/
            return S.Cast(SB.spellMindFlay, ret => U.isUnitValid(Unit, Range) /*Interrupt = 1 Chain = 1 U.activeEnemies() <= 5*/);
        }
        #endregion

        #region [Method] - Shadow Word Pain React
        public static Composite ShadowWordPainReact(WoWUnit Unit, double Range)
        {   /*shadow_word_pain,cycle_targets=1,max_cycle_targets=5,if=miss_react&ticks_remain<=1*/
            return S.Cast(SB.spellShadowWordPain, ret => U.isUnitValid(Unit, Range) /*U.activeEnemies() == 2 | <= 5*/);
        }
        #endregion

        #region [Method] - Shadow Word Pain AoE
        public static Composite ShadowWordPainAoE(WoWUnit Unit, double Range)
        {   /*shadow_word_pain,cycle_targets=1,max_cycle_targets=5,if=miss_react&!ticking*/
            return S.Cast(SB.spellShadowWordPain, ret => U.isUnitValid(Unit, Range) /*U.activeEnemies() == 2 | <= 5*/);
        }
        #endregion

        #region [Method] - Vampiric Touch React
        public static Composite VampiricTouchReact(WoWUnit Unit, double Range)
        {   /*vampiric_touch,cycle_targets=1,max_cycle_targets=5,if=remains<cast_time+tick_time&miss_react*/
            return S.Cast(SB.spellVampiricTouch, ret => U.isUnitValid(Unit, Range) /*U.activeEnemies() == 2 | <= 5*/);
        }
        #endregion

        #region [Method] - Vampiric Touch AoE
        public static Composite VampiricTouchAoE(WoWUnit Unit, double Range)
        {   /*vampiric_touch,cycle_targets=1,max_cycle_targets=5,if=remains<cast_time&miss_react*/
            return S.Cast(SB.spellVampiricTouch, ret => U.isUnitValid(Unit, Range) /*U.activeEnemies() == 2 | <= 5*/);
        }
        #endregion

        //private static bool VampiricEmbrace
        //vampiric_embrace,if=shadow_orb=3&health.pct<=40

        //private static bool Devouring Plague
        //devouring_plague,if=shadow_orb=3&ticks_remain<=1

        //private static bool MindSpike
        //mind_spike,if=active_enemies<=5&buff.surge_of_darkness.react=2

        //private static bool Halo
        //halo,if=talent.halo.enabled&target.distance<=30&target.distance>=17

        //private static bool Cascade
        //cascade_damage,if=talent.cascade.enabled&(active_enemies>1|(target.distance>=25&stat.mastery_rating<15000)|target.distance>=28)&target.distance<=40&target.distance>=11

        //private static bool DivineStar
        //divine_star,if=talent.divine_star.enabled&(active_enemies>1|stat.mastery_rating<3500)&target.distance<=24

        //wait,sec=cooldown.shadow_word_death.remains,if=target.health.pct<20&cooldown.shadow_word_death.remains<0.5&active_enemies<=1
        //wait,sec=cooldown.mind_blast.remains,if=cooldown.mind_blast.remains<0.5&active_enemies<=1

        //private static bool MindSpike
        //mind_spike,if=buff.surge_of_darkness.react&active_enemies<=5

        //private static bool MindSear
        //mind_sear,chain=1,interrupt=1,if=active_enemies>=3

        //private static bool MindFlay
        //mind_flay,chain=1,interrupt=1

        //private static bool ShadowWordDeath
        //shadow_word_death,moving=1

        //private static bool MindBlast
        //mind_blast,moving=1,if=buff.divine_insight_shadow.react&cooldown_react

        //private static bool DivineStar
        //divine_star,moving=1,if=talent.divine_star.enabled&target.distance<=28

        //private static bool Cascade
        //cascade_damage,moving=1,if=talent.cascade.enabled&target.distance<=40

        //private static bool ShadowWordPainMoving
        //shadow_word_pain,moving=1

        //private static bool Dispersion
        //dispersion
    }
}
